<?php session_start(); ?>

      <?php 
	if ($_SERVER["REQUEST_METHOD"] == "POST")
	{  	
	/* --------------------------------------------------------------------- */
            // mysql connection
            $user = $_SESSION['user'];
            $password = $_SESSION['password'];
            $database = $_SESSION['database'];
            $host = $_SESSION['host'];

            $condb = mysqli_connect($host, $user, $password, $database);
        /* --------------------------------------------------------------------- */
            
		
		if(isset($_POST['courseid']) and isset($_POST['lecturename']))
		{
                    
                    
		    $courseid= $_POST['courseid']; // sets variables to insert into database
		    $lectureName=$_POST['lecturename'];
                   
                    
		    $id = $_SESSION['id'];// this variable is used to relate to specific user
                    
		    if(mysqli_connect_errno()) 
     		    {
      		    echo "connection failed " . mysqli_connect_error();
     		    }
                
		    $insert_1= "INSERT  INTO LECTURE (COURSE_ID,  LECTURE_NAME) VALUES ('$courseid','$lectureName');"; //
		
		    if (!mysqli_query($condb,$insert_1))
 		    {
  		    die('Error: NO COURSE ' . mysqli_error($condb));
  		    } else {
                    
                    $select="SELECT LAST_INSERT_ID()";
                    
                    $result = mysqli_query($condb, $select);
                    
                    while ($row = mysqli_fetch_array($result)) {
                        $lectureid=$row['LAST_INSERT_ID()'];
                    }
                    //echo "successfully inserted lecture".$lectureName." name data into".$courseid;
                    }
	       } 
	 
	} ?>
                                <tr>
                                    <td><?php echo $lectureName; ?></td>
                                    <td class="rightborder">
                                        <form action="deletelecture.php" method="post" id="id<?php echo  $lectureid; ?>" name="delete" class="delete">
                                            <!-- hidden field contains values from database used to identify the course to remove-->
                                            <input type="hidden" value="<?php echo $lectureid; ?>" name="lectureid" id="lectureid"></input>
                                            <input type="submit" value="ta bort"/>
                                        </form>
                                    </td>
                                    <td class="leftborder">
                                        <form action="../lectures/editlectures.php" method="post">
                                            <!-- hidden field contains values from database used to identify the course to remove-->
                                            <input type="hidden" value="<?php echo $lectureid; ?>" name="lectureid" id="lectureid"></input>
                                            <input type="submit" value="Redigera" onclick="return confirm('vill du redigera lektionen ?')"/>
                                        </form>
                                    </td>

                                </tr>                